<template>
	<view>
				<!--列表-->
				<view class="p-2 animate__animated animate__fadeIn animate__fast" >
					<!--头像昵称  |  关注按钮-->
					<view style="display: flex; align-items: center;justify-content: space-between">
						<view>
							<!-- 头像 -->
							<image :src="item.userpic" style="width: 65rpx;height: 65rpx;border-radius: 100%;margin-right: 20rpx;"lazy-load @click="openSpace"></image>
							<!-- 昵称|发布时间 -->
							<view style="">
								<view class=""style="font-size: 30rpx;line-height:1.3;">{{item.username}}</view>
								<text style="color: #9d9589;font-size:25rpx ;line-height:1.3">{{item.newstime}}</text>
							</view>
						</view>
						<view style="width: 90rpx;height: 50rpx;display: flex;align-items: center;justify-content: center;border-radius: 5rpx;background-color: #1296db;color:#FFFFFF;"class="animate__animated animate__faster"  hover-class="animate__jello" @click="follow" v-if="!item.isFollow">
							关注
						</view>
					</view>
					<!-- 标题 -->
					<view style="font-size: 30rpx;margin: 10rpx 0;"@click="openDetail">{{item.title}}</view>
					<!-- 帖子详情 -->
					<slot>
						<!-- 图片 -->
							<image v-if="item.titlepic" :src="item.titlepic[0]" style="width: 100%;height: 150rpx;border-radius: 5rpx;"mode="widthFix"@click="
							openDetail()"></image>
					</slot>
					<!-- 按钮 -->
					<view style="display: flex;align-items: center;">
						<view style="flex: 1;"class="animate__animated animate__faster "hover-class="animate__jello text-main" @click="doSupport('support')" :class="item.support.type==='support'?'supportactive':''">
							<text class="iconfont icon-dianzan2"style="margin-right: 20rpx;"></text>
							<text>{{item.support.support_count}}</text>
						</view>
						<view style="flex: 1;"class="animate__animated animate__faster "hover-class="animate__jello text-main"@click="doSupport('unsupport')":class="item.support.type==='unsupport'?'supportactive':''">
							<text class="iconfont icon-cai"style="margin-right: 20rpx;"></text>
							<text>{{item.support.unsupport_count}}</text>
						</view>
						<view style="flex: 1;"class="animate__animated animate__faster "hover-class="animate__jello"@click="doComment">
							<text class="iconfont icon-pinglun2" style="margin-right: 20rpx;"></text>
							<text>{{item.comment_count}}</text>
						</view>
						<view style="flex: 1;"class="animate__animated animate__faster "hover-class="animate__jello"@click="doShare">
							<text class="iconfont icon-fenxiang"style="margin-right: 20rpx;"></text>
							<text>{{item.share_num}}</text>
						</view>
					</view>
				</view>
				
	    
	   
	</view>
</template>

<script>
	export default{
		props:{
			item:Object,
			index:{
				type:Number,
				default:-1
			},
			isdetail: {
				type:Boolean,
				default:false 
			},
			friend:Array
		},
		data() {
			return {
				list:[]
			}
		},
		
		methods:{
			
			//打开个人空间
			 openSpace(){
				 
				uni.navigateTo({
					url:'../../pages/user-space/user-space'
				});
				console.log(this.item._id)
			},
			//关注
			async	follow(){
				console.log(11111111111111)
				console.log(this.friend)
				console.log(11111111111111)
				console.log(this.item.id)
				this.friend.push(this.item.id)
				console.log(this.friend)
				const res = await uniCloud.callFunction({
										name: 'friend',
										data: {
											action: 'update',
											id:this.$store.state.loginsStatus,
											friend: this.friend
										}
									});
									
				const q = await uniCloud.callFunction({
										name: 'msg',
										data: {
											action: 'add',
											id:this.$store.state.loginsStatus,
											id1:this.item.id,
											list:[]
										}
									});	
				const w = await uniCloud.callFunction({
										name: 'msg',
										data: {
											action: 'add',
											id:this.item.id,
											id1:this.$store.state.loginsStatus,
											list:[]
										}
									});	
				
													
				this.checkAuth(()=>{
					//通知父组件
				this.$emit('follow',this.index)
				})
				
			},
			//详情页
			openDetail(){
				//处于详情页
				if(	this.isdetail)return; 
				uni.navigateTo({
					url:'../../pages/detail/detail?detail='+JSON.stringify(this.item)+'&_id='+this.item._id,
				})
			},
			//顶踩操作
			doSupport(type){
				this.checkAuth(()=>{
						this.$emit('dosupport',
						
					{
						type:type,
						index:this.index
					})
				})
				
			},
			//评论
			doComment(){
				this.checkAuth(()=>{
					if(!this.isdetail){
					return this.openDetail()
				}
				this.$emit('doComment')
				})
				
			},
			//分享
			doShare(){
				this.checkAuth(()=>{
					if(!this.isdetail){
					return this.openDetail()
				}
				this.$emit('doShare')
				})
				
			}
		}
	}
</script>

<style>
	.supportactive{
		color: #1296db;
	}
</style>
